﻿using SQLServer.BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Tenancy.Helper;

namespace Tenancy.Server
{
    /// <summary>
    /// Hbung_MatchSearchList 的摘要说明
    /// </summary>
    public class Hbung_MatchSearchList : IHttpHandler
    {
        Machine Mac = new Machine();
        /// <summary>
        /// 首页模糊查询接口 
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string HB_Condition = context.Request.Params["Condition"];
            string StrWhere ="1=1 ";
            if(!string.IsNullOrEmpty(HB_Condition))
            {
                StrWhere += string.Format(" and brand like '%{0}%' or modelCode like '%{0}%' or PlatformHeight like '%{0}%' or DriveWay like '%{0}%' or ParkAddressCurProvince like '%{0}%' or ParkAddressCurCity like '%{0}%' or ParkAddressCurCounty like '%{0}%' or ParkAddressCurDetail like '%{0}%'",HB_Condition);
            }
            //页数
            string CurPage = context.Request.Params["PageIndex"];
            if (string.IsNullOrEmpty(CurPage))
            {
                context.Response.Write(GenerClass.SetParamErrorJsData("PageIndex值为空"));
                return;
            }
            int Indexnum = 0;
            if (!string.IsNullOrEmpty(CurPage))
            {
                if (!int.TryParse(CurPage, out Indexnum) || Indexnum < 0)
                {
                    context.Response.Write(GenerClass.SetParamErrorJsData("PageIndex值不是数字"));
                    return;
                }
            }
            //每页多少数据
            string ageSize = context.Request.Params["PageSize"];
            int Sizenum = 0;
            if (string.IsNullOrEmpty(ageSize))
            {
                context.Response.Write(GenerClass.SetParamErrorJsData("pageSize值为空"));
                return;
            }
            if (!string.IsNullOrEmpty(ageSize))
            {
                if (!int.TryParse(ageSize, out Sizenum) || Sizenum < 0)
                {
                    context.Response.Write(GenerClass.SetParamErrorJsData("pageSize值不是数字"));
                    return;
                }
            }
            DataTable ProjectMac = Mac.IEProjectList(StrWhere, Indexnum, Sizenum, "id");
            context.Response.Write(GenerClass.GetJsonTable("查询成功", JsonHelper.DataTableToJSON(ProjectMac)));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}